// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from "vue";
// 引入 Cube-ui
import Cube from "cube-ui";
Vue.use(Cube);

// 引入 Mint-ui
import "mint-ui/lib/style.css";
import MintUI from "mint-ui";
Vue.use(MintUI);

// 引入 loaingAnimation
import loading from "./assets/js/loading";
Vue.prototype.loading = loading;

// 引入 toastLib
import toastLib from "./assets/js/toastLib";
Vue.prototype.toastLib = toastLib;

// 引入 iview
import iView from "iview";
import "iview/dist/styles/iview.css";
Vue.use(iView);
// 引入axios  vue-axios
import axios from "axios";
import VueAxios from "vue-axios";
Vue.use(VueAxios, axios);

// import request from './assets/js/request'
// Vue.prototype.request = request

// 测试服务器
// axios.defaults.baseURL = 'http://test.act.yuepinyuemei.com/';
// 正式服务器

// axios.defaults.baseURL = 'https://act.yuepinyuemei.com/'

// 测试服
//target: "http://test.act.yuepinyuemei.com/api/upload/img",  //测试服图片上传

axios.defaults.headers.post["Content-Type"] =
  "application/x-www-form-urlencoded;charset=UTF-8";

// 配置全局图片域名
Vue.prototype.imgUrl = "https://img.yuepinyuemei.com/";

// 引入时间格式化
import "./assets/js/time_format";
import moment from "moment";
Vue.filter("moment", function(value, formatString) {
  formatString = formatString || "YYYY-MM-DD HH:mm:ss";
  return moment.unix(value).format(formatString);
});
// 引入 vue-clipboard2
import VueClipboard from "vue-clipboard2";
Vue.use(VueClipboard);

// 返回控制不能到登录页
router.beforeEach((to, from, next) => {
  let token = localStorage.token || "";
  axios.defaults.headers.post["Authorization"] =
    "Bearer " + localStorage.getItem("token") || "";

  axios.defaults.headers.get["Authorization"] =
    "Bearer " + localStorage.getItem("token") || "";

  if (token == "" && to.path != "/" && to.path == "evaluate") {
    next({
      path: "/login"
    });
  } else if (token != "" && to.path == "/") {
    next({
      path: "/indexPage"
    });
  } else if (
    from.path.split(":")[0] == "/billdetail" &&
    to.path == "/createdBill"
  ) {
    next({
      path: "/indexPage"
    });
  } else {
    next();
  }
});

import App from "./App";
import router from "./router";

Vue.config.productionTip = false;

/* eslint-disable no-new */
new Vue({
  el: "#app",
  router,
  template: "<App/>",
  components: {
    App
  }
});
